package com.hxzy.mapper;

import com.hxzy.controller.admin.product.req.ProductReq;
import com.hxzy.controller.admin.product.resp.ProductResp;
import com.hxzy.controller.mobile.product.req.MobileProductReq;
import com.hxzy.controller.mobile.product.resp.MobileProductResp;
import com.hxzy.entity.Product;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @author Administrator
* @description 针对表【product(商品信息)】的数据库操作Mapper
* @createDate 2023-06-28 16:38:45
* @Entity com.hxzy.entity.Product
*/
public interface ProductMapper extends BaseMapper<Product> {

    List<ProductResp> search(@Param(value = "req") ProductReq req);

    List<MobileProductResp> mobileSearch(@Param(value = "req")  MobileProductReq req);

    /**
     * 根据主键查询数据（悲观锁）
     * @param dishId
     * @return
     */
    Product pessimisticLockById(Long dishId);

    /**
     * 减库存
     * @param dishId
     * @param n
     * @return
     */
    @Update(value = "update product set num=num-#{n} where id=#{dishId}")
    int  descNum(@Param(value = "dishId") Long dishId, @Param(value = "n")int n);
}




